

import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;

public class State2 {

    private Integer id;
    private boolean accepting;
    private Map<Character,Set<Integer>> transitions;

    public State2() {
        this.id=-1;
        this.accepting=false;
        this.transitions = new HashMap<Character,Set<Integer>>();
    }
    
    public State2( Integer i, boolean a ) {
        this.id = i;
        this.accepting = a;
        this.transitions=new HashMap<Character,Set<Integer>>();
    }

    public Integer getID() { return this.id; }
    public boolean isAccepting() { return this.accepting; }

    public void setAccept(boolean a) { this.accepting = a; }


    public void addTransition( Character ch, Integer target ) {
        if( !this.transitions.containsKey(ch) ) this.transitions.put(ch, new HashSet<Integer>());
        this.transitions.get(ch).add(target);
    }

    public void addTransition( Character ch, State2 target ) {
        if( !this.transitions.containsKey(ch) ) this.transitions.put(ch, new HashSet<Integer>());
        this.transitions.get(ch).add(target.getID());
    }


    public void removeTransition( Character ch ) {
        if( this.transitions.containsKey(ch) ) {
            this.transitions.remove(ch);
        }
    }

    public void removeTransition( Character ch, Integer target ) {
        if( this.transitions.containsKey(ch) ) {
            this.transitions.get(ch).remove(target);
        }
    }
    public Map<Character,Set<Integer>> getTransitions(){
        return transitions;
    }

    public Set<Integer> getTargets(Character ch) {
        if ( this.transitions.containsKey(ch) ) return this.transitions.get(ch);
        else return null;
    }
    
    public String toString() {
        String s = "";
        s += this.id;
        if(accepting){
            s +=" (o)";
        }else{
            s +=" (x)";
        }
        s += "  --  ";
        
        for ( Map.Entry<Character, Set<Integer>> entry : transitions.entrySet()){
            if (entry.getKey() != '\0'){
                s +=  entry.getKey() + ":" + entry.getValue();
            }else{
                s +=  "ㅌ:" + entry.getValue();
            }
            s += "  ";
        }
        return s;
    }
    
    public void test() {
        System.out.println(transitions.size());
        System.out.println(transitions.keySet());
        System.out.println(transitions.entrySet());
    }

};


